#include <transforms.h>
#include <stdlib.h>

matrix4x4_t *
compile_pipeline( matrix4x4_t *matrices[] )
{
  matrix4x4_t *result, *tmp, **itr;

  if ( matrices[ 0 ] == NULL )
    return NULL;

  result = matrix4x4_copy( *matrices[ 0 ] );
  if ( matrices[ 1 ] == NULL )
    return result;

  for ( itr=matrices+1; *itr != NULL; itr++ )
    {
      tmp = matrix4x4_multiply( *result, **itr );
      matrix4x4_free( result );
      result = tmp;
    }
  return result;
}

void
free_pipeline_matrices( matrix4x4_t *matrices[] )
{
  matrix4x4_t **itr;

  for ( itr=matrices; *itr != NULL; itr++ )
    matrix4x4_free( *itr );
}

